package com.yanqu.road.entity.kowloon.sanxiao;

import com.yanqu.road.entity.kowloon.common.Vec2;
import com.yanqu.road.entity.kowloon.enums.eKowloonBlockType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class KowloonGameData {

    private int chapterId;                                        // 关卡ID
    private int sectionId;                                       // 当前波次
    private List<KowloonSkill> skillList = new ArrayList<>();                      // 生效的技能
    private List<List<KowloonBlock>> blockList = new ArrayList<>();                // 盘面
    private int useStep;                                        // 使用步数
    private int leftStep;                                       // 剩余步数
    private List<Integer> chooseSkill = new ArrayList<>();      // 可选技能
    private int skillBlockIndex;                                // 可选技能对应的福袋位置
    private long beginTime;
    private long showNo;                                         // 表现编号,客户端验证用
    private int hp;                                             // 当前血量
    private int maxHp;                                          // 最大血量
    private List<Integer> bossCol = new ArrayList<>();          // boss路径预警

    private List<Vec2> bossBirthPosList = new ArrayList<>();

    private List<KowloonChooseHeroData> chooseHeroList = new ArrayList<>(); // 上阵的好汉

    private int guideDropIndex = 0; //新手引导掉落累计

    public KowloonGameData clone() {
        KowloonGameData data = new KowloonGameData();
        data.setChapterId(getChapterId());
        data.setSectionId(getSectionId());
        List<KowloonSkill> tmpSkill = new ArrayList<>();
        for (KowloonSkill skill : getSkillList()) {
            tmpSkill.add(skill.clone());
        }
        data.setSkillList(tmpSkill);
        data.setSkillBlockIndex(getSkillBlockIndex());
        List<List<KowloonBlock>> tmpBlock = new ArrayList<>();
        for (List<KowloonBlock> list : getBlockList()) {
            List<KowloonBlock> tmp = new ArrayList<>();
            for (KowloonBlock block : list) {
                tmp.add(block.clone());
            }
            tmpBlock.add(tmp);
        }
        data.setBlockList(tmpBlock);
        data.setUseStep(getUseStep());
        data.setLeftStep(getLeftStep());
        data.setChooseSkill(new ArrayList<>(getChooseSkill()));
        data.setBeginTime(getBeginTime());
        data.setHp(getHp());
        data.setMaxHp(getMaxHp());
        data.setBossCol(new ArrayList<>(getBossCol()));
        data.setShowNo(getShowNo());
        List<KowloonChooseHeroData> heroDataList = new ArrayList<>();
        for (KowloonChooseHeroData heroData : this.chooseHeroList) {
            heroDataList.add(heroData.clone());
        }
        data.setChooseHeroList(heroDataList);
        for (Vec2 vec2 : bossBirthPosList) {
            data.getBossBirthPosList().add(vec2.clone());
        }
        return data;
    }


    public int getChapterId() {
        return chapterId;
    }

    public void setChapterId(int chapterId) {
        this.chapterId = chapterId;
    }

    public int getSectionId() {
        return sectionId;
    }

    public void setSectionId(int sectionId) {
        this.sectionId = sectionId;
    }

    public List<KowloonSkill> getSkillList() {
        return skillList;
    }

    public void setSkillList(List<KowloonSkill> skillList) {
        this.skillList = skillList;
    }

    public KowloonSkill getSkill(int skillId) {
        for (KowloonSkill kowloonSkill : skillList) {
            if (kowloonSkill.getSkillId() == skillId) {
                return kowloonSkill;
            }
        }
        return null;
    }

    public void addSkill(KowloonSkill skill) {
        this.skillList.add(skill);
    }

    public List<List<KowloonBlock>> getBlockList() {
        return blockList;
    }

    public void setBlockList(List<List<KowloonBlock>> blockList) {
        this.blockList = blockList;
    }

    public int getUseStep() {
        return useStep;
    }

    public void setUseStep(int useStep) {
        this.useStep = useStep;
    }

    public int getLeftStep() {
        return leftStep;
    }

    public void setLeftStep(int leftStep) {
        this.leftStep = leftStep;
    }

    public void addLeftStep(int step) {
        this.leftStep += step;
    }

    /**
     * 步数减1
     */
    public void decLeftStep() {
        this.leftStep -= 1;
        this.useStep += 1;
    }

    public List<Integer> getChooseSkill() {
        return chooseSkill;
    }

    public void setChooseSkill(List<Integer> chooseSkill) {
        this.chooseSkill = chooseSkill;
    }

    public int getSkillBlockIndex() {
        return skillBlockIndex;
    }

    public void setSkillBlockIndex(int skillBlockIndex) {
        this.skillBlockIndex = skillBlockIndex;
    }

    public long getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getMaxHp() {
        return maxHp;
    }

    public void setMaxHp(int maxHp) {
        this.maxHp = maxHp;
    }

    public List<Integer> getBossCol() {
        return bossCol;
    }

    public void setBossCol(List<Integer> bossCol) {
        this.bossCol = bossCol;
    }

    public long getShowNo() {
        return showNo;
    }

    public void setShowNo(long showNo) {
        this.showNo = showNo;
    }

    public void addHpMax(int hp) {
        this.maxHp += hp;
        this.hp += hp;
    }

    public int hpRevert(int hp) {
        if (this.hp + hp >= this.maxHp) {
            this.hp = this.maxHp;
        } else {
            this.hp += hp;
        }

        return this.hp;
    }

    public int subHp(int hp) {
        if (this.hp - hp <= 0) {
            this.hp = 0;
        } else {
            this.hp -= hp;
        }
        return this.hp;
    }

    public List<KowloonChooseHeroData> getChooseHeroList() {
        return chooseHeroList;
    }

    public void setChooseHeroList(List<KowloonChooseHeroData> chooseHeroList) {
        this.chooseHeroList = chooseHeroList;
    }

    public KowloonChooseHeroData getChooseHero(int heroId) {
        for (KowloonChooseHeroData heroData : chooseHeroList) {
            if (heroData.getHeroId() == heroId) {
                return heroData;
            }
        }
        return null;
    }

    public List<Vec2> getBossBirthPosList() {
        return bossBirthPosList;
    }

    public void setBossBirthPosList(List<Vec2> bossBirthPosList) {
        this.bossBirthPosList = bossBirthPosList;
    }

    public int getGuideDropIndex() {
        return guideDropIndex;
    }

    public void setGuideDropIndex(int guideDropIndex) {
        this.guideDropIndex = guideDropIndex;
    }

    public int incGuideDropIndex() {
        this.guideDropIndex++;
        return this.guideDropIndex;
    }
}
